import java.util.*;

class MyComparator implements Comparator<String> {
    @Override
    public int compare(String o1, String o2) {
        return o1.compareTo(o2);
    }
}

public class day230514 {
    // 电话号码

    // 使用 数组存放结果集,使用 Array.sort() 排序, 用 伪删除 去重
    public static void main0(String[] args) {
        String[] arr = {"0", "1", "2ABC", "3DEF", "4GHI", "5JKL", "6MNO", "7PQRS", "8TUV", "9WXYZ"};
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int n = sc.nextInt();
            // 用来存放结果
            String[] list = new String[n];

            for (int i = 0; i < n; i++) {
                // 接收一个号码
                String s = sc.next();
                // 存放处理后的号码
                StringBuilder sb = new StringBuilder();
                // 进行处理
                for (int j = 0; j < s.length(); j++) {
                    char ch = s.charAt(j);
                    for (int k = 0; k < 10; k++) {
                        // '-' 这个符号不处理
                        if (arr[k].indexOf(ch) != -1) {
                            sb.append(k);
                            break;
                        }
                    }
                }
                // 插入'-' , 使格式为 xxx-xxxx
                list[i] = sb.insert(3, '-').toString();
            }

            // 排序
            Arrays.sort(list);

            // 去重, 伪删除
            boolean[] flag = new boolean[n];
            for (int i = 0; i < n - 1; i++) {
                if (list[i].equals(list[i + 1])) {
                    flag[i] = true;
                }
            }

            // 打印结果集
            for (int i = 0; i < n; i++) {
                if (!flag[i]) {
                    System.out.println(list[i]);
                }
            }
            System.out.println();
        }
    }

    // 使用数组存放结果
    public static void main1(String[] args) {
        String[] arr = {"0", "1", "2ABC", "3DEF", "4GHI", "5JKL", "6MNO", "7PQRS", "8TUV", "9WXYZ"};
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int n = sc.nextInt();
            // 用来存放结果
            ArrayList<String> list = new ArrayList<>();

            for (int i = 0; i < n; i++) {
                // 接收一个号码
                String s = sc.next();
                // 存放处理后的号码
                StringBuilder sb = new StringBuilder();
                // 进行处理
                for (int j = 0; j < s.length(); j++) {
                    char ch = s.charAt(j);
                    for (int k = 0; k < 10; k++) {
                        if (arr[k].indexOf(ch) != -1) {
                            sb.append(k);
                            break;
                        }
                    }
                }
                sb.insert(3, '-');
                // contains 去重
                if (!list.contains(sb.toString())) {
                    list.add(sb.toString());
                }
            }

            // 排序
            list.sort(new MyComparator());

            // 打印结果
            for (String s : list) {
                System.out.println(s);
            }
            System.out.println();
        }
    }

    // 使用 TreeSet , 解决排序和去重
    public static void main(String[] args) {
        String[] arr = {"0", "1", "2ABC", "3DEF", "4GHI", "5JKL", "6MNO", "7PQRS", "8TUV", "9WXYZ"};
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int n = sc.nextInt();
            // 用来存放结果
            TreeSet<String> list = new TreeSet<>();

            for (int i = 0; i < n; i++) {
                // 接收一个号码
                String s = sc.next();
                // 存放处理后的号码
                StringBuilder sb = new StringBuilder();
                // 进行处理
                for (int j = 0; j < s.length(); j++) {
                    char ch = s.charAt(j);
                    for (int k = 0; k < 10; k++) {
                        if (arr[k].indexOf(ch) != -1) {
                            sb.append(k);
                            break;
                        }
                    }
                }

                list.add(sb.insert(3, '-').toString());
            }

            // 打印结果
            for (String s : list) {
                System.out.println(s);
            }
            System.out.println();
        }
    }

    // 求和

}
